﻿#pragma once

#include <thread>
#include <boost/asio.hpp>
#include "server_base.h"

class ServerAsio : public ServerBase {
public:
	ServerAsio();
	virtual void Start() override;
	virtual void Stop() override;
	virtual void Wait() override;
	virtual unsigned short Port() const override;

private:
	void PrepareAccept();
	void OnAccept(boost::system::error_code error, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
	void OnRead(boost::system::error_code error, std::shared_ptr<boost::asio::ip::tcp::socket> socket, size_t size);
	void OnWrite(boost::system::error_code error, std::shared_ptr<boost::asio::ip::tcp::socket> socket, size_t size);
	std::thread thread_;
	boost::asio::io_context io_context_;
	boost::asio::ip::tcp::acceptor acceptor_;
	std::vector<char> read_buffer_;
	std::vector<char> write_buffer_;

};
